/*
 * Copyright 2008 Federal Emergency Management Agency
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 *    
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *  
 */
package gov.fema.hazus.bdc.client.settings;

import gov.fema.hazus.bdc.client.common.entities.AbstractClickListener;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;

public class PaginationControls extends Composite {

	private FlexTable table;
	private HTML first;
	private HTML last;
	private HTML total;
	
	private HTML next;
	private HTML previous;
	
	private AbstractClickListener nextClickListener;
	private AbstractClickListener previousClickListener;
    private SettingsConstants constants;
	
	public PaginationControls(AbstractClickListener n, AbstractClickListener p)
	{
	
        constants = (SettingsConstants)GWT.create(SettingsConstants.class);
        
		nextClickListener = n;
		previousClickListener = p;
		
		// create the table
		table = new FlexTable();
		table.setStyleName("pagination");
		
		// create clickable elements
		next = new HTML(">>");
		next.setStyleName("navigation");
		next.addClickListener(n);
		
		previous = new HTML("<<");
		previous.setStyleName("navigation");
		previous.addClickListener(p);
		
		// create data
		first = new HTML();
		first.setStyleName("numbering");
		last = new HTML();
		last.setStyleName("numbering");
		total = new HTML();
		total.setStyleName("numbering");
		
		// put data in table
		table.setWidget(0, 1, previous);
		table.setWidget(0, 2, first);
		table.setWidget(0, 3, new HTML("-"));
		table.setWidget(0, 4, last);
		table.setWidget(0, 5, new HTML( "of" ));
		table.setWidget(0, 6, total);
		table.setWidget(0, 7, next);
		
		initWidget(table);
		
	}
	
	public void setFirst(String value)
	{
		first.setText(value);
	}
	
	public void setLast(String value)
	{
		last.setText(value);
	}
	
	public void setTotal(String value)
	{
		total.setText(value);
	}
	
	public void hideNext()
	{
		next.setVisible(false);
	}
	
	public void showNext()
	{
		next.setVisible(true);
	}
	
	public void hidePrevious()
	{
		previous.setVisible(false);
	}
	
	public void showPrevious()
	{
		previous.setVisible(true);
	}

	public AbstractClickListener getNextClickListener() {
		return nextClickListener;
	}

	public void setNextClickListener(AbstractClickListener nextClickListener) {
		this.nextClickListener = nextClickListener;
	}

	public AbstractClickListener getPreviousClickListener() {
		return previousClickListener;
	}

	public void setPreviousClickListener(AbstractClickListener previousClickListener) {
		this.previousClickListener = previousClickListener;
	}	
	
}
